package com.boguan.web.controller.system;


import com.boguan.common.core.controller.BaseController;
import com.boguan.common.core.domain.AjaxResult;
import com.boguan.system.domain.Protocol;
import com.boguan.system.service.ISysProtocolService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 协议相关
 */
@RestController
@RequestMapping("/system/protocol")
public class SysProtocolController extends BaseController {

    @Autowired
    private ISysProtocolService sysProtocolService;

    /**
     * 保存用户协议
     *
     * @param protocol
     * @return
     */
    @ApiOperation("保存用户协议")
    @PostMapping("/save/user")
    public AjaxResult saveUserProtocol(@Validated @RequestBody Protocol protocol) {
        protocol.setType(1);
        protocol.setCreateTime(new Date());
        return toAjax(sysProtocolService.saveProtocol(protocol));
    }

    /**
     * 保存隐私协议
     *
     * @param protocol
     * @return
     */
    @ApiOperation("保存隐私协议")
    @PostMapping("/save/privacy")
    public AjaxResult savePrivacyProtocol(@RequestBody Protocol protocol) {
        protocol.setType(2);
        return toAjax(sysProtocolService.saveProtocol(protocol));
    }

    /**
     * 查询用户协议
     *
     * @return
     */
    @ApiOperation("查看用户协议")
    @GetMapping("/user")
    public AjaxResult getUserProtocol() {
        return AjaxResult.success(sysProtocolService.getProtocol(1));
    }

    /**
     * 查询隐私协议
     *
     * @return
     */
    @ApiOperation("查看隐私协议")
    @GetMapping("privacy")
    public AjaxResult getPrivacyProtocol() {
        return AjaxResult.success(sysProtocolService.getProtocol(2));
    }
}
